
<?php
/**
 * Template Name: login
 *
 */
$richiesta = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url=get_bloginfo('url')."/";
$si = false;

if ($richiesta == $url) {
    $si = TRUE;
}
if(!$si){
    
get_header();
}
?>

<?php if(!$si){ ?>
<div id="contenuti">
    <?php } ?>
<?php if (is_user_logged_in()) { ?>
        <h5 style="margin-left: 35px;">
        <?php
        global $user_ID;
        $loggato = get_userdata($user_ID);
        $host = get_bloginfo('url');
        echo "Sei già connesso come: $loggato->display_name  <br />";
        echo 'Vai alla pagina <a href="' . $host . '/professionisti" title="Vai alla pagina per i Professionisti">Professionisti</a><br /> ';
        echo '<a href="' . wp_logout_url(get_permalink()) . '/wp-login.php?action=logout" title="Esci da questo account">Logout</a>';
        ?>
        </h5>
    <?php } else { ?>

        <form action="" method="" name="log-in" id="log-in">
            <h5 style="">Accedi</h5>
            <input type="text" name="user-name" id="user-name" class="login_input" value="<?php echo wp_specialchars($_POST['user-name'], 1); ?>" />
            <input type="password" name="password" class="login_input" id="password" />
            <div class="login_dimenticato"><a href="<?php bloginfo('url'); ?>/wp-login.php?action=lostpassword">Hai dimenticato la password?</a></div>
            <input id="vai" type="image" src="<?php bloginfo('template_url') ?>/img/butt_login.png"  class="login_button"/>
            <input type="hidden" id="action" name="action" value="accesso" />
            <div class="login_professionista"><a href="<?php bloginfo('url'); ?>/registrazione-professionisti">Sei un professionista? Iscriviti!</a></div>
        </form>
    <?php } ?>
    <?php if(!$si){ ?>
</div>
<?php } ?>
<script>
    var blurl= '<?php echo get_option('siteurl'); ?>';
    $(document).ready(function(){
        $('#vai').click(function(evt){
            evt.preventDefault();
            $.ajax({
                type: 'POST',
                data: $('#log-in').serialize(),
                url: blurl+"/wp-admin/admin-ajax.php?action=accesso",
                success: function(data){
                    //alert(data);
                    if (data.ok == '3') {
                        Dialog(data.message); 
                        $('form input[type=text],textarea, input[type=password]').val('');
                        $('#home-professionisti-login').hide();
                    }else if(data.ok==0){
                        Dialog(data.message);
                        $.each(data.campi, function(i,e){
                            // $('form .obb').show();
                            var c= '#req_'+e;
                            //alert(c);
                            $(c).show();
                        });
                    }
                },
                error: function(data){
                    alert(data);
                }                
            }); 
        });
        function Dialog(str){
            str = '<div class="alert"><div class="chiudi"><a href="#"></a></div><div class="boxGradiente gradient">'+str+'</div></div>';
            
            $.blockUI({
                //                css: {
                //                    border: '4px solid',
                //                    borderColor:'#fff',
                //                    padding: '0',
                //                    cursor: 'default',
                //                    left: '49%',
                //                    margin:'-250px 0 0 -256px',
                //                    top: '50%',
                //                    width: '512px',
                //                    padding: '20px',
                //                    color: 'black',
                //                    fontFamily: 'Arial, Helvetica, sans-serif',
                //                    textAlign: 'left',
                //                    fontSize: '13px'
                //                },
                message: str,
                //                overlayCSS: {
                //                    cursor: 'default',
                //                    backgroundColor:'#000',
                //                    opacity:'0.3'
                //                },
                onBlock: function(){
                    $(".chiudi").click(function() {
                        $.unblockUI();
                    });
                }
            });
        }
    });
</script>

<?php
if(!$si){
get_footer();
}
?>